//第二部：创建各大功能

//1、加载dataBase文件
var db = require('./dataBase.js');

// ====================================课程管理========================
//获取课程管理 数据
classCourse = (req, res) => {
	var sql = 'SELECT * FROM class_course';
	var _data = [];
	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '获取失败',
				'list': data
			})
		} else {
			res.send({
				code: 200,
				msg: '获取成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack)
}

// 课程管理-添加课程
addClassCourse = (req, res) => {
	var {
		serial_number,
		name,
		cover,
		state_s,
		price,
		brief,	
		teacher_init,
		up_time,
		phone,
		sech_time
	} = req.query;

	var _data = [serial_number, name, cover, state_s, price, brief, teacher_init,up_time,phone,sech_time];

	var sql = 'SELECT * FROM class_course WHERE serial_number="' + serial_number + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '添加失败'
			})
		} else {
			// console.log(data)
			if (data[0] != serial_number) {
				//添加语句
				var _sql = 'INSERT INTO class_course (serial_number,name,cover,state_s,price,brief,teacher_init,up_time,phone,sech_time) VALUE (?,?,?,?,?,?,?,?,?,?)';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '信息已存在'
						})
					} else {
						res.send({
							code: 1,
							msg: '添加成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 0,
					msg: '数据已存在'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}

// 课程管理—————删除功能
delClassCourse = (req, res) => {
	var serNum = req.query.serNum;

	var _data = [serNum];

	//设置sql语句
	var sql = 'SELECT * FROM class_course WHERE serial_number="' + _data[0] + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作失败'
			})
		} else {
			//删除操作
			if (data[0].serial_number == serNum) {
				var _sql = 'DELETE FROM class_course WHERE serial_number=?';
				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '删除失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '删除成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}

// 课程管理-修改
editClassCourse = (req, res) => {
	var { serial_number, name, cover, state_s, price} = req.query;
	// console.log(id)
	var _data = [serial_number, name, cover, state_s, price];

	var sql = 'SELECT * FROM class_course WHERE serial_number="' + serial_number + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作错误'
			})
		} else {
			// console.log(id)
			if (data[0].serial_number == serial_number) {

				var _sql = 'UPDATE class_course SET serial_number=?,name=?,cover=?,state_s=?,price=? WHERE serial_number="' + serial_number + '"';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '修改失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '修改成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 3,
					msg: '修改失败'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}

// 课程管理-查询
sechClassCourse = (req, res) => {
	var { sech_one, sech_two,sech_three } = req.query;

	var _data = [sech_one, sech_two,sech_three]
	var sql = 'SELECT serial_number=?,name=?,state_s=?,up_time=? FROM class_course WHERE state_s="' + sech_one + '" OR name="' + sech_two + '" OR up_time="' + sech_three +'"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 0,
				msg: '没有查询的数据',
				'list': data
			})
		} else {
			res.send({
				code: 1,
				msg: '查询成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack);
}
// ===============================================订单管理-订单-------------------=--------

//获取订单管理-订单 数据
odOrder = (req, res) => {
	var sql = 'SELECT * FROM class_course';
	var _data = [];
	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '获取失败',
				'list': data
			})
		} else {
			res.send({
				code: 200,
				msg: '获取成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack)
}

// 订单管理-订单————删除功能
delOdOrder = (req, res) => {
	var serNum = req.query.serNum;

	var _data = [serNum];

	//设置sql语句
	var sql = 'SELECT * FROM class_course WHERE serial_number="' + _data[0] + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作失败'
			})
		} else {
			//删除操作
			if (data[0].serial_number == serNum) {
				var _sql = 'DELETE FROM class_course WHERE serial_number=?';
				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '删除失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '删除成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}

// 订单管理-订单查询
sechOdOrder = (req, res) => {
	var { sech_one, sech_two,sech_three } = req.query;
	
	var _data = [sech_one, sech_two,sech_three]
	var sql = 'SELECT serial_number,name,state_s,up_time FROM class_course WHERE state_s="' + sech_one + '" OR up_time="' + sech_two + '" OR name="' + sech_three + '" OR serial_number="' + sech_three + '"';
	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 0,
				msg: '没有查询的数据',
				'list': data
			})
		} else {
			res.send({
				code: 1,
				msg: '查询成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack);
}

// ================================================订单管理-退款==========================================
//获取订单管理-退款 数据
odRefund = (req, res) => {
	var sql = 'SELECT * FROM class_course';
	var _data = [];
	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '获取失败',
				'list': data
			})
		} else {
			res.send({
				code: 200,
				msg: '获取成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack)
}
// 订单管理-退款查询
sechOdRefund = (req, res) => {

	var { sech_one, sech_two } = req.query;
	
	var _data = [sech_one, sech_two,sech_three]
	var sql = 'SELECT serial_number,name,up_time FROM class_course WHERE up_time="' + sech_one + '" OR name="' + sech_two + '" OR serial_number="' + sech_two + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 0,
				msg: '没有查询的数据',
				'list': data
			})
		} else {
			res.send({
				code: 1,
				msg: '查询成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack);
}

// ===========================================用户管理-——学员==================================
// 获取用户管理-学员 数据
userStudent = (req, res) => {
	var sql = 'SELECT * FROM user_student';
	var _data = [];
	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '获取失败',
				'list': data
			})
		} else {
			res.send({
				code: 200,
				msg: '获取成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack)
}
// 用户管理-学员————添加学员
addUserTeacher = (req, res) => {
	var {
		stu_ID,
		name,
		phone,
		stu_pyp,
		up_pyp,
		stu_time
	} = req.query;

	var _data = [stu_ID, name, phone, stu_pyp,up_pyp,stu_time];

	var sql = 'SELECT * FROM user_student WHERE user_ID="' + stu_ID + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '添加失败'
			})
		} else {
			// console.log(data)
			if (data[0] != stu_ID) {
				//添加语句
				var _sql = 'INSERT INTO user_student (stu_ID, name, phone, stu_pyp,up_pyp,stu_time) VALUE (?,?,?,?,?,?)';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '信息已存在'
						})
					} else {
						res.send({
							code: 1,
							msg: '添加成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 0,
					msg: '数据已存在'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// 用户管理-学员————删除功能
delUserStudent = (req, res) => {
	var stuID = req.query.stuID;

	var _data = [stuID];

	//设置sql语句
	var sql = 'SELECT * FROM user_student WHERE stu_ID="' + _data[0] + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作失败'
			})
		} else {
			//删除操作
			if (data[0].stu_ID == stuID) {
				var _sql = 'DELETE FROM user_student WHERE stu_ID=?';
				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '删除失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '删除成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}

// 用户管理-学员修改
editUserStudent = (req, res) => {
	var {stu_ID, name, phone, stu_pyp,up_pyp} = req.query;
	// console.log(id)
	var _data = [stu_ID, name, phone, stu_pyp,up_pyp];

	var sql = 'SELECT * FROM user_student WHERE stu_ID="' + stu_ID + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作错误'
			})
		} else {
			if (data[0].stu_ID == stu_ID) {

				var _sql = 'UPDATE user_student SET stu_ID=?,name=?,phone=?,stu_pyp=?,up_pyp=? WHERE stu_ID="' + stu_ID + '"';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '修改失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '修改成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 3,
					msg: '修改失败'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// 用户管理-学员查询
sechUserStudent = (req, res) => {
	var {sech_one, sech_two, sech_three} = req.query;

	var _data = [sech_one, sech_two]
	var sql = 'SELECT stu_ID,name,phone,stu_time,stu_pyp FROM user_student WHERE stu_time="' + sech_one + '" OR name="' + sech_two + '" OR od_number="' + sech_two + '" OR phone="' + sech_two + '" OR stu_pyp="' + sech_three + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 0,
				msg: '没有查询的数据',
				'list': data
			})
		} else {
			res.send({
				code: 1,
				msg: '查询成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack);
}
// ============================================= 用户管理-讲师=========================================
// 获取用户管理-讲师 数据
userTeacher = (req, res) => {
	var sql = 'SELECT * FROM user_teacher';
	var _data = [];
	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '获取失败',
				'list': data
			})
		} else {
			res.send({
				code: 200,
				msg: '获取成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack)
}
// 用户管理-讲师——添加讲师
addUserTeacher = (req, res) => {
	var {
		lec_name,
		lec_head,
		lec_brief,
		detail,
		add_time
	} = req.query;

	var _data = [lec_name, lec_head, lec_brief, detail,add_time];

	var sql = 'SELECT * FROM user_teacher WHERE lec_name="' + lec_name + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '添加失败'
			})
		} else {
			// console.log(data)
			if (data[0] != lec_name) {
				//添加语句
				var _sql = 'INSERT INTO user_teacher (lec_name,lec_head,lec_brief,detail,add_time) VALUE (?,?,?,?,?)';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '信息已存在'
						})
					} else {
						res.send({
							code: 1,
							msg: '添加成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 0,
					msg: '数据已存在'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// 用户管理-讲师————删除功能
delUserTeacher = (req, res) => {
	var lecName = req.query.lecName;

	var _data = [lecName];

	//设置sql语句
	var sql = 'SELECT * FROM user_teacher WHERE lec_name="' + _data[0] + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作失败'
			})
		} else {
			//删除操作
			if (data[0].lec_name == lecName) {
				var _sql = 'DELETE FROM user_teacher WHERE lec_name=?';
				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '删除失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '删除成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// 用户管理-讲师修改
editUserTeacher = (req, res) => {
	var { lec_name, lec_head, lec_brief, detail,add_time } = req.query;
	// console.log(id)
	var _data = [lec_name, lec_head, lec_brief, detail, add_time];

	var sql = 'SELECT * FROM user_teacher WHERE lec_name="' + lec_name + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作错误'
			})
		} else {
			if (data[0].lec_name == lec_name) {

				var _sql = 'UPDATE user_teacher SET lec_name=?,lec_head=?,lec_brief=?,detail=?,add_time=? WHERE lec_name="' + lec_name + '"';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '修改失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '修改成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 3,
					msg: '修改失败'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// 用户管理-讲师查询
sechUserTeacher = (req, res) => {
	var { sech_one, sech_two } = req.query;

	var _data = [sech_one, sech_two]
	var sql = 'SELECT lec_name,add_time FROM user_teacher WHERE add_time="' + sech_one + '" OR lec_name="' + sech_two + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 0,
				msg: '没有查询的数据',
				'list': data
			})
		} else {
			res.send({
				code: 1,
				msg: '查询成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack);
}

// = ===================================================获取资讯管理-轮播图================================
// 获取资讯管=理-轮播图 数据
infCarousel = (req, res) => {
	var sql = 'SELECT * FROM inf_carousel';
	var _data = [];

	//设置回调函数
	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '获取失败',
				'list': data
			})
		} else {
			res.send({
				code: 200,
				msg: '获取成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack)
}
// 资讯管理—轮播图————删除功能
delInfCarousel = (req, res) => {
	var _name = req.query.name;

	var _data = [_name];

	//设置sql语句
	var sql = 'SELECT * FROM inf_carousel WHERE name="' + _data[0] + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作失败'
			})
		} else {
			//删除操作
			if (data[0].name == _name) {
				var _sql = 'DELETE FROM inf_carousel WHERE name=?';
				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '删除失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '删除成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// 资讯管理-轮播图——添加轮播图
addInfCarousel = (req, res) => {
	var {
		name,
		picture,
		explain,
		pic_link,
		add_time
	} = req.query;

		add_time
	var _data = [name, picture, explain, pic_link,add_time];

	var sql = 'SELECT * FROM inf_carousel WHERE name="' + name + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '添加失败'
			})
		} else {
			// console.log(data)
			if (data[0] != name) {
				//添加语句
				var _sql = 'INSERT INTO inf_carousel (name,picture,explain,pic_link,add_time) VALUE (?,?,?,?,?)';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '信息已存在'
						})
					} else {
						res.send({
							code: 1,
							msg: '添加成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 0,
					msg: '数据已存在'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// 资讯管理-轮播图修改
editInfCarousel = (req, res) => {
	var { name, picture, explain, pic_link,add_time } = req.query;
	// console.log(id)
	var _data = [name, picture, explain, pic_link,add_time];

	var sql = 'SELECT * FROM inf_carousel WHERE name="' + name + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作错误'
			})
		} else {
			if (data[0].name == name) {

				var _sql = 'UPDATE inf_carousel SET name=?,picture=?,explain=?,pic_link=?,add_time=? WHERE name="' + name + '"';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '修改失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '修改成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 3,
					msg: '修改失败'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// ================================================== 资讯管理-文章========================================
// 获取质询管理-文章 数据
infArticle = (req, res) => {
	var sql = 'SELECT * FROM inf_article';
	var _data = [];

	//设置回调函数
	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '获取失败',
				'list': data
			})
		} else {
			res.send({
				code: 200,
				msg: '获取成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack)
}
// 资讯管理-文章————删除功能
delInfArticle = (req, res) => {
	var titleS = req.query.title_s;

	var _data = [titleS];

	//设置sql语句
	var sql = 'SELECT * FROM inf_article WHERE title="' + _data[0] + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作失败'
			})
		} else {
			//删除操作
			if (data[0].title == titleS) {
				var _sql = 'DELETE FROM inf_article WHERE title=?';
				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '删除失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '删除成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// 资讯管理-文章——添加文章
addInfArticle = (req, res) => {
	var {
		title,
		cover,
		describe,
		text_content,
		add_time
	} = req.query;

	var _data = [title, cover, describe, text_content, add_time];

	var sql = 'SELECT * FROM inf_article WHERE title="' + title + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '添加失败'
			})
		} else {
			// console.log(data)
			if (data[0] != title) {
				//添加语句
				var _sql = 'INSERT INTO inf_article (title,cover,describe,text_content,add_time) VALUE (?,?,?,?,?)';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '信息已存在'
						})
					} else {
						res.send({
							code: 1,
							msg: '添加成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 0,
					msg: '数据已存在'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// 资讯管理-文章修改
editInfArticle = (req, res) => {
	var { title, cover, describe, text_content, add_time } = req.query;
	// console.log(id)
	var _data = [title, cover, describe, text_content, add_time];

	var sql = 'SELECT * FROM inf_article WHERE title="' + title + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作错误'
			})
		} else {
			if (data[0].title == title) {

				var _sql = 'UPDATE inf_article SET title=?,cover=?,describe=?,text_content=?,add_time=? WHERE title="' + title + '"';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '修改失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '修改成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 3,
					msg: '修改失败'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}

// ==============================================促销管理-秒杀活动========================================
// 获取促销管理-秒杀活动 数据
promKill = (req, res) => {
	var sql = 'SELECT * FROM prom_kill';
	var _data = [];

	//设置回调函数
	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '获取失败',
				'list': data
			})
		} else {
			res.send({
				code: 200,
				msg: '获取成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack)
}
// 促销管理-秒杀活动————删除动能
delPromKill = (req, res) => {
	var killNum = req.query.killNum;

	var _data = [killNum];

	//设置sql语句
	var sql = 'SELECT * FROM prom_kill WHERE kill_num="' + _data[0] + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作失败'
			})
		} else {
			//删除操作
			if (data[0].kill_num == killNum) {
				var _sql = 'DELETE FROM prom_kill WHERE kill_num=?';
				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '删除失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '删除成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// 促销管理-秒杀活动——添加秒杀活动
addPromKill = (req, res) => {
	var {
		kill_num,
		kill_title,
		kill_cover,
		kill_state,
		state_time,
		end_time
	} = req.query;

	var _data = [kill_num, kill_title, kill_cover, kill_state, state_time, end_time];

	var sql = 'SELECT * FROM prom_kill WHERE kill_num="' + kill_num + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '添加失败'
			})
		} else {
			// console.log(data)
			if (data[0] != kill_num) {
				//添加语句
				var _sql = 'INSERT INTO prom_kill (kill_num, kill_title, kill_cover, kill_state, state_time, end_time) VALUE (?,?,?,?,?,?)';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '信息已存在'
						})
					} else {
						res.send({
							code: 1,
							msg: '添加成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 0,
					msg: '数据已存在'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// 促销管理-秒杀活动修改
editPromKill = (req, res) => {
	var { kill_num, kill_title, kill_cover, kill_state, state_time, end_time } = req.query;
	// console.log(id)
	var _data = [kill_num, kill_title, kill_cover, kill_state, state_time, end_time];

	var sql = 'SELECT * FROM prom_kill WHERE kill_num="' + kill_num + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作错误'
			})
		} else {
			if (data[0].kill_num == kill_num) {

				var _sql = 'UPDATE prom_kill SET kill_num=?,kill_title=?,kill_cover=?,kill_state=?,state_time=?,end_time=? WHERE kill_num="' + kill_num + '"';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '修改失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '修改成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 3,
					msg: '修改失败'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// =================================================================促销管理-秒杀活动-课程设置=================================================
// 获取促销管理-秒杀活动-课程设置 数据
promCourseSet = (req, res) => {
	var sql = 'SELECT * FROM prom_kill';
	var _data = [];

	//设置回调函数
	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '获取失败',
				'list': data
			})
		} else {
			res.send({
				code: 200,
				msg: '获取成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack)
}
// 促销管理-秒杀活动-课程设置————删除功能
delPromCourseSet = (req, res) => {
	var killNum = req.query.killNum;

	var _data = [killNum];

	//设置sql语句
	var sql = 'SELECT * FROM prom_kill WHERE kill_num="' + _data[0] + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作失败'
			})
		} else {
			//删除操作
			if (data[0].kill_num == killNum) {
				var _sql = 'DELETE FROM prom_kill WHERE kill_num=?';
				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '删除失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '删除成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}

// 促销管理-秒杀活动-课程设置修改
editPromCourseSet = (req, res) => {
	var { kill_num, kill_title, kill_cover, kill_state, state_time, end_time } = req.query;
	// console.log(id)
	var _data = [kill_num, kill_title, kill_cover, kill_state, state_time, end_time];

	var sql = 'SELECT * FROM prom_kill WHERE kill_num="' + kill_num + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作错误'
			})
		} else {
			if (data[0].kill_num == kill_num) {

				var _sql = 'UPDATE prom_kill SET kill_num=?,kill_title=?,kill_cover=?,kill_state=?,state_time=?,end_time=? WHERE kill_num="' + kill_num + '"';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '修改失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '修改成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 3,
					msg: '修改失败'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// ================================================================促销管理-优惠卷================================================
// 获取促销管理-优惠卷 数据
promCoupon = (req, res) => {
	var sql = 'SELECT * FROM prom_coupon';
	var _data = [];

	//设置回调函数
	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '获取失败',
				'list': data
			})
		} else {
			res.send({
				code: 200,
				msg: '获取成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack)
}

// 促销管理-优惠卷——添加优惠卷
addPromCoupon = (req, res) => {
	var {
		prom_num,
		name,
		prom_sill,
		use_scope,
		prom_number,
		state_time,
		end_time,
		prom_day,
		prom_type,
		face_value,
		state_s
	} = req.query;

	var _data = [prom_number, name, prom_sill, use_scope,prom_num, state_time,end_time,prom_day,prom_type, face_value, state_s];

	var sql = 'SELECT * FROM prom_coupon WHERE name="' + name + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '添加失败'
			})
		} else {
			// console.log(data)
			if (data[1] != name) {
				//添加语句
				var _sql = 'INSERT INTO prom_coupon (prom_number,name,prom_sill,use_scope,prom_num,state_time,end_time,prom_day,prom_type,face_value,state_s) VALUE (?,?,?,?,?,?,?,?,?,?,?)';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '信息已存在'
						})
					} else {
						res.send({
							code: 1,
							msg: '添加成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 0,
					msg: '数据已存在'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// 促销管理-优惠卷————删除功能
delPromCoupon = (req, res) => {
	var _name = req.query.name;

	var _data = [_name];

	//设置sql语句
	var sql = 'SELECT * FROM prom_coupon WHERE name="' + _data[1] + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作失败'
			})
		} else {
			//删除操作
			if (data[0].name == _name) {
				var _sql = 'DELETE FROM prom_coupon WHERE name=?';
				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '删除失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '删除成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}

// 促销管理-优惠卷查询
sechPromCoupon = (req, res) => {
	var { sech_one, sech_two, sech_three } = req.query;

	var _data = [sech_one, sech_two, sech_three]
	var sql = 'SELECT name,prom_num,state_time,end_time,prom_type,state_s WHERE prom_type="' + sech_one + '" OR state_time="' + sech_two + '" OR end_time="' + sech_two + '" OR name="' + sech_three + '" OR prom_num="' + sech_three + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 0,
				msg: '没有查询的数据',
				'list': data
			})
		} else {
			res.send({
				code: 1,
				msg: '查询成功',
				'list': data
			})
		}
	}
	db.ConnectData(sql, _data, callBack);
}
// 促销管理-优惠卷修改
editPromCoupon = (req, res) => {
	var {prom_num,name,prom_sill,use_scope,prom_day,face_value,state_s } = req.query;
	// console.log(id)
	var _data = [prom_num,name,prom_sill,use_scope,prom_day,face_value,state_s];

	var sql = 'SELECT * FROM prom_coupon WHERE name="' + name + '"';

	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作错误'
			})
		} else {
			if (data[1].name == name) {

				var _sql = 'UPDATE prom_coupon SET prom_num=?,name=?,prom_sill=?,use_scope=?,prom_day=?,face_value=?,state_s=? WHERE name="' + name + '"';

				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '修改失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '修改成功'
						})
					}
				}
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 3,
					msg: '修改失败'
				})
			}
		}
	}
	db.ConnectData(sql, [], callBack)
}
// ===========================================================注册功能======================================
getRegister = (req, res) => {
	//使用mysql语句（用ES6中的对象解构）
	var {
		user,
		pass
	} = req.body

	//定义赋值请求参数
	var _data = [user, pass]
	// console.log(_data)
	//设置sql语句（查看是否已注册）
	var sql = 'SELECT *FROM login WHERE user="' + user + '"';

	//设置回调函数
	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 403,
				masg: '操作错误'
			})
		} else {
			if (data[0] === undefined) { //表示没有注册
				//插入字段
				var _sql = 'INSERT INTO login (user, pass) VALUE (?,?)';

				//设置回调函数
				var _callBack = (err, result) => {
					if (err) {
						res.send({
							code: 0,
							msg: '注册失败'
						})
					} else {
						res.send({
							code: 1,
							msg: '注册成功'
						})
					}
				}
				//执行插入语句
				db.ConnectData(_sql, _data, _callBack)
			} else {
				res.send({
					code: 2,
					msg: '账号已存在'
				})
			}
		}
	}
	//执行查询语句
	db.ConnectData(sql, [], callBack)
}

// ======================================================================登录功能===============================
getLogin = (req, res) => {
	var {
		user,
		pass
	} = req.body;
	var _data = [user, pass];
	var sql = 'SELECT pass FROM login WHERE user="' + user + '"';
	var callBack = (err, data) => {
		if (err) {
			res.send({
				code: 404,
				msg: '操作错误',
				isOk: 0 //此字段用来判断是否登入
			})
		} else {
			if (data[0] === undefined) { //表示数据库中没有这个账号
				res.send({
					code: 304,
					msg: '用户不存在',
					isOk: 2,
					'list': data
				})
			} else {
				//数据表中有这个账号，然后判断密码是否正确
				if (data[0].pass == _data[1]) { //密码正确
					res.send({
						code: 200,
						msg: '登入成功',
						isOk: 1,
						'list': data
					})
				} else { //表示密码错误
					res.send({
						code: 300,
						msg: '密码错误',
						isOk: 3,
						'list': data
					})
				}
			}
		}
	}
	db.ConnectData(sql, _data, callBack)
}

//3、暴露功能函数===========================================================================
module.exports = {
	// ---------------------渲染全部------------------
	// 课程管理
	classCourse,
	// 订单管理-订单
	odOrder,
	// 订单管理-退款
	odRefund,
	// 用户管理-学员
	userStudent,
	// 用户管理-讲师
	userTeacher,
	// 资讯管理-轮播图
	infCarousel,
	// 质询管理-文章
	infArticle,
	// 促销管理-秒杀活动
	promKill,
	// 促销管理-秒杀活动-课程设置
	promCourseSet,
	// 促销管理-优惠卷
	promCoupon,
	// ======================== 登录注册=============
	// 注册功能
	getRegister,
	// 登录功能
	getLogin,
	// ---------------------------------删除----------------------
	// 课程管理—————删除功能
	delClassCourse,
	// 订单管理-订单————删除功能
	delOdOrder,
	// 用户管理-学员————删除功能
	delUserStudent,
	// 用户管理-讲师————删除功能
	delUserTeacher,
	// 资讯管理—轮播图————删除功能
	delInfCarousel,
	// 资讯管理-文章————删除功能
	delInfArticle,
	// 促销管理-秒杀活动————删除动能
	delPromKill,
	// 促销管理-秒杀活动-课程设置————删除功能
	delPromCourseSet,
	//  促销管理-优惠卷————删除功能
	delPromCoupon,
	// ----------------------------添加----------------------
	// 课程管理-添加课程
	addClassCourse,
	// 用户管理-讲师——添加讲师
	addUserTeacher,
	// 资讯管理-轮播图——添加轮播图
	addInfCarousel,
	// 资讯管理-文章——添加文章
	addInfArticle,
	// 促销管理-秒杀活动——添加秒杀活动
	addPromKill,
	// 促销管理-优惠卷——添加优惠卷
	addPromCoupon,
	//---------------------------- 查询--------------------
	// 课程管理-查询
	sechClassCourse,
	// 订单管理-订单查询
	sechOdOrder,
	// 订单管理-退款查询
	sechOdRefund,
	// 用户管理-学员查询
	sechUserStudent,
	// 用户管理-讲师查询
	sechUserTeacher,
	// 促销管理-优惠卷查询
	sechPromCoupon,
	// ----------------------------修改--------------------
	// 课程管理-修改
	editClassCourse,
	// 用户管理-学员修改
	editUserStudent,
	// 用户管理-讲师修改
	editUserTeacher,
	// 资讯管理-轮播图修改
	editInfCarousel,
	// 资讯管理-文章修改
	editInfArticle,
	// 促销管理-秒杀活动修改
	editPromKill,
	// 促销管理-秒杀活动-课程设置修改
	editPromCourseSet,
	// 促销管理-优惠卷修改
	editPromCoupon
}
